---
title: Destroy Engine
description: Learn how to use the destroy method in @embedpdf/engines to clean up all global resources.
searchable: true
---

# destroy

Shuts down the PDF engine and frees all global resources used by the WebAssembly library.

## Signature

```typescript
destroy(): PdfTask<boolean>;
````

## Description

This method is the counterpart to `initialize`. It should be called when your application is completely finished with all PDF operations and the engine instance is no longer needed. Calling `destroy` ensures that all memory allocated by the PDFium library is released, preventing memory leaks in your application.

After `destroy` has been called, the engine instance **cannot be used again**.

## Parameters

This method takes no parameters.

## Returns

`PdfTask<boolean>`

A **`Task`** that resolves with `true` once the engine and its resources have been successfully cleaned up.

See [Concepts: Tasks](../tasks.md) for more on how to handle asynchronous operations.

## Example

```typescript
// Assuming 'engine' is an initialized engine instance that is no longer needed

async function cleanupPdfProcessor() {
  try {
    await engine.destroy().toPromise();
    console.log('PDF engine has been shut down and resources are freed.');
  } catch (error) {
    console.error('Failed to destroy PDF engine:', error);
  }
}

// Call this when your component unmounts or your application closes.
cleanupPdfProcessor();
```

## See Also

  - [initialize](initialize.md)

